package com.qidian.mes.defect.service.serviceImpl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qidian.mes.defect.mapper.DefectMapper;
import com.qidian.mes.defect.service.DefectService;
import com.qidianit.common.pojo.MESResult;
import com.qidianit.common.util.Constant;
import com.qidianit.mes.pojo.Defect;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author 泽华
 * @Description
 * @Time 2024-10-16 16:38
 */
@Service
public class DefectServiceImpl implements DefectService {
    @Autowired
    private DefectMapper defectMapper;
    @Override
    public MESResult save(Defect defect) {
        return defectMapper.insert(defect) == 1?MESResult.success():MESResult.error();
    }

    @Override
    public MESResult delete(Long defectId) {
        Defect defect = new Defect();
        defect.setDefectId(defectId);
        defect.setDefectStatus(Constant.DATA_STATUS_DELETE);
        return MESResult.isSuccess(defectMapper.deleteById(defect));
    }

    @Override
    public MESResult deletes(Long[] defectIds) {
        return MESResult.success(200,"ok",defectMapper.deletesById(defectIds));
    }

    @Override
    public MESResult update(Defect defect) {
        return MESResult.success(200,"ok",defectMapper.update(defect));
    }

    @Override
    public MESResult list(String defectDescription,String defectType,String defectGrade,int page, int limit) {
        // 开启分页  参数1： 页码  参数2： 每页大小
        PageHelper.startPage(page,limit);
        // 查询全部
        List<Defect> defects = defectMapper.selectList(defectDescription,defectType,defectGrade);
        PageInfo<Defect> pageInfo = new PageInfo<>(defects);
        // 将pageInfo对象设置到MESResult中
        return MESResult.success(pageInfo);
    }

    @Override
    public MESResult selectById(Long defectId) {
        return MESResult.success(defectMapper.selectById(defectId));

    }


}
